package com.phospherus.flow.service

import com.phospherus.flow.entity.*
import com.phospherus.flow.repository.*
import org.apache.commons.lang.StringUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

/**
 * @author songjinlong
 * @version 1.0
 * @since 2018/1/4
 */
@Service
class DocumentProcessService : FormInstBaseService() {
    @Autowired
    lateinit var documentProcessFdConfirmRepository: DocumentProcessFdConfirmRepository
    @Autowired
    lateinit var documentProcessFdNoticeRepository: DocumentProcessFdNoticeRepository
    @Autowired
    lateinit var documentProcessFdnFcDffContactRepository: DocumentProcessFdnFcDffContactRepository
    @Autowired
    lateinit var documentprocessDeliDetailRepository: DocumentprocessDeliDetailRepository
    @Autowired
    lateinit var documentprocessFdnLccDflContactRepository: DocumentprocessFdnLccDflContactRepository
    @Autowired
    lateinit var documentprocessCcCustomsDeclarationInvoiceRepository: DocumentprocessCcCustomsDeclarationInvoiceRepository
    @Autowired
    lateinit var documentprocessCcCdiTableRepository: DocumentprocessCcCdiTableRepository
    @Autowired
    lateinit var documentprocessCcDeclarationFormRepository: DocumentprocessCcDeclarationFormRepository
    @Autowired
    lateinit var documentprocessCcDfTableRepository: DocumentprocessCcDfTableRepository
    @Autowired
    lateinit var documentprocessCcCustomsDeclarationContractRepository: DocumentprocessCcCustomsDeclarationContractRepository
    @Autowired
    lateinit var documentprocessCcCustomsDeclarationBoxRepository: DocumentprocessCcCustomsDeclarationBoxRepository
    @Autowired
    lateinit var documentprocessCcCdbTableRepository: DocumentprocessCcCdbTableRepository
    @Autowired
    lateinit var documentprocessCcDeclarationElementsRepository: DocumentprocessCcDeclarationElementsRepository
    @Autowired
    lateinit var documentprocessCcDeDefRepository: DocumentprocessCcDeDefRepository
    @Autowired
    lateinit var documentprocessCcLetterOfDeliveryRepository: DocumentprocessCcLetterOfDeliveryRepository
    @Autowired
    lateinit var documentprocessAskInvoiceRepository: DocumentprocessAskInvoiceRepository
    @Autowired
    lateinit var documentprocessAskiTableRepository: DocumentprocessAskiTableRepository
    @Autowired
    lateinit var documentprocessCollectionDataRepository: DocumentprocessCollectionDataRepository

    override fun getFormInstServiceName(): String = "documentprocess"

    override fun save(map: MutableMap<String, Any>) {
        var formInstId = map["formInstId"] as Long

        //---------------------工厂发货----------------------
        var documentProcessFdMap = map["documentprocess_fd"] as Map<String, Any>?
        if (documentProcessFdMap != null) {
            //出厂确认
            var documentProcessFdConfirmMap = documentProcessFdMap["documentProcess_fd_confirm"] as Map<String, Any>?
            if (documentProcessFdConfirmMap != null) {
                var documentProcessFdConfirm = createEntityByMap<DocumentProcessFdConfirm>(documentProcessFdConfirmMap, DocumentProcessFdConfirm::class.java)
                documentProcessFdConfirm.formInstId = formInstId
                documentProcessFdConfirm = documentProcessFdConfirmRepository.save(documentProcessFdConfirm)
                if (StringUtils.isNotBlank(documentProcessFdConfirmMap["attachedFiles"] as? String )) {
                    attachedFileService.addFormInstAttachedFile(documentProcessFdConfirmMap["attachedFiles"].toString(), formInstId, "documentprocess_fd_confirm", documentProcessFdConfirm.id)
                }
            }
            //发货通知单
            var documentProcessFdNoticeMap = documentProcessFdMap["documentProcess_fd_notice"] as Map<String, Any>?
            if (documentProcessFdNoticeMap != null) {
                var documentProcessFdNotice = createEntityByMap<DocumentProcessFdNotice>(documentProcessFdNoticeMap, DocumentProcessFdNotice::class.java)
                documentProcessFdNotice.formInstId = formInstId
                documentProcessFdNotice = documentProcessFdNoticeRepository.save(documentProcessFdNotice)
                if (StringUtils.isNotBlank(documentProcessFdNoticeMap["attachedFiles"] as? String )) {
                    attachedFileService.addFormInstAttachedFile(documentProcessFdNoticeMap["attachedFiles"].toString(), formInstId, "documentprocess_fd_notice", documentProcessFdNotice.id)
                }
                //------
                var documentProcessFdnFcDffContactList = documentProcessFdNoticeMap["documentprocess_fdn_fc_dff_contacts"] as List<Map<String, Any>>?
                var ftcProductDetails: List<DocumentProcessFdnFcDffContact>? = null
                if (documentProcessFdnFcDffContactList != null) {
                    ftcProductDetails = documentProcessFdnFcDffContactList.mapTo(ArrayList(), {
                        with(createEntityByMap<DocumentProcessFdnFcDffContact>(it, DocumentProcessFdnFcDffContact::class.java)) {
                            this.id = null
                            this.formInstId = formInstId
                            this.dpfdId = documentProcessFdNotice.id
                            this
                        }
                    })
                }
                var tables1 = documentProcessFdnFcDffContactRepository.findByFormInstIdAndDpfdId(formInstId, documentProcessFdNotice.id!!)
                documentProcessFdnFcDffContactRepository.delete(tables1)
                if(ftcProductDetails != null){
                    documentProcessFdnFcDffContactRepository.save(ftcProductDetails)
                }

                //------
                var documentprocessDeliDetailList = documentProcessFdNoticeMap["documentprocess_deliDetail"] as List<Map<String, Any>>?
                var deliDetails: List<DocumentprocessDeliDetail>? = null
                if (documentprocessDeliDetailList != null) {
                    deliDetails = documentprocessDeliDetailList.mapTo(ArrayList(), {
                        with(createEntityByMap<DocumentprocessDeliDetail>(it, DocumentprocessDeliDetail::class.java)) {
                            this.id = null
                            this.formInstId = formInstId
                            this.dpfdId = documentProcessFdNotice.id
                            this
                        }
                    })
                }
                var tables2 = documentprocessDeliDetailRepository.findByFormInstIdAndDpfdId(formInstId, documentProcessFdNotice.id!!)
                documentprocessDeliDetailRepository.delete(tables2)
                if(deliDetails != null){
                    documentprocessDeliDetailRepository.save(deliDetails)
                }

                //------
                var documentprocessFdnLccDflContactList = documentProcessFdNoticeMap["documentprocess_fdn_lcc_dfl_contacts"] as List<Map<String, Any>>?
                var fdnLccDflContactLists: List<DocumentprocessFdnLccDflContact>? = null
                if (documentprocessFdnLccDflContactList != null) {
                    fdnLccDflContactLists = documentprocessFdnLccDflContactList.mapTo(ArrayList(), {
                        with(createEntityByMap<DocumentprocessFdnLccDflContact>(it, DocumentprocessFdnLccDflContact::class.java)) {
                            this.id = null
                            this.formInstId = formInstId
                            this.dpfdId = documentProcessFdNotice.id
                            this
                        }
                    })
                }
                var tables3 = documentprocessFdnLccDflContactRepository.findByFormInstIdAndDpfdId(formInstId, documentProcessFdNotice.id!!)
                documentprocessFdnLccDflContactRepository.delete(tables3)
                if(fdnLccDflContactLists != null){
                    documentprocessFdnLccDflContactRepository.save(fdnLccDflContactLists)
                }
            }
        }
        //---------------------工厂发货----------------------
        //---------------------单证员报关----------------------
        var documentprocessCcMap = map["documentprocess_cc"] as Map<String, Any>?
        if (documentprocessCcMap != null) {
            //货运委托书
            var documentprocessCcLetterOfDeliveryMap = documentprocessCcMap["documentprocess_cc_letterOfDelivery"] as Map<String, Any>?
            if (documentprocessCcLetterOfDeliveryMap != null) {
                var documentprocessCcLetterOfDelivery = createEntityByMap<DocumentprocessCcLetterOfDelivery>(documentprocessCcLetterOfDeliveryMap, DocumentprocessCcLetterOfDelivery::class.java)
                documentprocessCcLetterOfDelivery.formInstId = formInstId
                documentprocessCcLetterOfDelivery = documentprocessCcLetterOfDeliveryRepository.save(documentprocessCcLetterOfDelivery)
                if (StringUtils.isNotBlank(documentprocessCcLetterOfDeliveryMap["attachedFiles"] as? String )) {
                    attachedFileService.addFormInstAttachedFile(documentprocessCcLetterOfDeliveryMap["attachedFiles"].toString(), formInstId, "documentprocess_cc_letterOfDelivery", documentprocessCcLetterOfDelivery.id)
                }
            }
            //报关发票
            var documentprocessCcCustomsDeclarationInvoiceMap = documentprocessCcMap["documentprocess_cc_customsDeclarationInvoice"] as Map<String, Any>?
            if (documentprocessCcCustomsDeclarationInvoiceMap != null) {
                var documentprocessCcCustomsDeclarationInvoice = createEntityByMap<DocumentprocessCcCustomsDeclarationInvoice>(documentprocessCcCustomsDeclarationInvoiceMap, DocumentprocessCcCustomsDeclarationInvoice::class.java)
                documentprocessCcCustomsDeclarationInvoice.formInstId = formInstId
                documentprocessCcCustomsDeclarationInvoice = documentprocessCcCustomsDeclarationInvoiceRepository.save(documentprocessCcCustomsDeclarationInvoice)
                if (StringUtils.isNotBlank(documentprocessCcCustomsDeclarationInvoiceMap["attachedFiles"] as? String )) {
                    attachedFileService.addFormInstAttachedFile(documentprocessCcCustomsDeclarationInvoiceMap["attachedFiles"].toString(), formInstId, "documentprocess_cc_customsDeclarationInvoice", documentprocessCcCustomsDeclarationInvoice.id)
                }
                var documentprocessCcCdiTableList = documentprocessCcCustomsDeclarationInvoiceMap["documentprocess_cc_cdi_table"] as List<Map<String, Any>>?
                var documentprocessCcCdiTables: List<DocumentprocessCcCdiTable>? = null
                if (documentprocessCcCdiTableList != null) {
                    documentprocessCcCdiTables = documentprocessCcCdiTableList.mapTo(ArrayList(), {
                        with(createEntityByMap<DocumentprocessCcCdiTable>(it, DocumentprocessCcCdiTable::class.java)) {
                            this.id = null
                            this.formInstId = formInstId
                            this.cdiId = documentprocessCcCustomsDeclarationInvoice.id
                            this
                        }
                    })
                }
                var tables = documentprocessCcCdiTableRepository.findByFormInstIdAndCdiId(formInstId, documentprocessCcCustomsDeclarationInvoice.id!!)
                documentprocessCcCdiTableRepository.delete(tables)
                if(documentprocessCcCdiTables != null){
                    documentprocessCcCdiTableRepository.save(documentprocessCcCdiTables)
                }
            }

            //报关箱单
            var documentprocessCcCustomsDeclarationBoxMap = documentprocessCcMap["documentprocess_cc_customsDeclarationBox"] as Map<String, Any>?
            if (documentprocessCcCustomsDeclarationBoxMap != null) {
                var documentprocessCcCustomsDeclarationBox = createEntityByMap<DocumentprocessCcCustomsDeclarationBox>(documentprocessCcCustomsDeclarationBoxMap, DocumentprocessCcCustomsDeclarationBox::class.java)
                documentprocessCcCustomsDeclarationBox.formInstId = formInstId
                documentprocessCcCustomsDeclarationBox = documentprocessCcCustomsDeclarationBoxRepository.save(documentprocessCcCustomsDeclarationBox)
                if (StringUtils.isNotBlank(documentprocessCcCustomsDeclarationBoxMap["attachedFiles"] as? String )) {
                    attachedFileService.addFormInstAttachedFile(documentprocessCcCustomsDeclarationBoxMap["attachedFiles"].toString(), formInstId, "documentprocess_cc_customsDeclarationBox", documentprocessCcCustomsDeclarationBox.id)
                }
                var documentprocessCcCdbTableList = documentprocessCcCustomsDeclarationBoxMap["documentprocess_cc_cdb_table"] as List<Map<String, Any>>?
                var documentprocessCcCdbTables: List<DocumentprocessCcCdbTable>? = null
                if (documentprocessCcCdbTableList != null) {
                    documentprocessCcCdbTables = documentprocessCcCdbTableList.mapTo(ArrayList(), {
                        with(createEntityByMap<DocumentprocessCcCdbTable>(it, DocumentprocessCcCdbTable::class.java)) {
                            this.id = null
                            this.formInstId = formInstId
                            this.cdbId = documentprocessCcCustomsDeclarationBox.id
                            this
                        }
                    })
                }
                var tables = documentprocessCcCdbTableRepository.findByFormInstIdAndCdbId(formInstId, documentprocessCcCustomsDeclarationBox.id!!)
                documentprocessCcCdbTableRepository.delete(tables)
                if(documentprocessCcCdbTables != null){
                    documentprocessCcCdbTableRepository.save(documentprocessCcCdbTables)
                }
            }

            //报关合同委托书
            var documentprocessCcCustomsDeclarationContractMap = documentprocessCcMap["documentprocess_cc_customsDeclarationContract"] as Map<String, Any>?
            if (documentprocessCcCustomsDeclarationContractMap != null) {
                var documentprocessCcCustomsDeclarationContract = createEntityByMap<DocumentprocessCcCustomsDeclarationContract>(documentprocessCcCustomsDeclarationContractMap, DocumentprocessCcCustomsDeclarationContract::class.java)
                documentprocessCcCustomsDeclarationContract.formInstId = formInstId
                documentprocessCcCustomsDeclarationContract = documentprocessCcCustomsDeclarationContractRepository.save(documentprocessCcCustomsDeclarationContract)
                if (StringUtils.isNotBlank(documentprocessCcCustomsDeclarationContractMap["attachedFiles"] as? String )) {
                    attachedFileService.addFormInstAttachedFile(documentprocessCcCustomsDeclarationContractMap["attachedFiles"].toString(), formInstId, "documentprocess_cc_customsDeclarationContract", documentprocessCcCustomsDeclarationContract.id)
                }
            }

            //报关单
            var documentprocessCcDeclarationFormMap = documentprocessCcMap["documentprocess_cc_declarationForm"] as Map<String, Any>?
            if (documentprocessCcDeclarationFormMap != null) {
                var documentprocessCcDeclarationForm = createEntityByMap<DocumentprocessCcDeclarationForm>(documentprocessCcDeclarationFormMap, DocumentprocessCcDeclarationForm::class.java)
                documentprocessCcDeclarationForm.formInstId = formInstId
                documentprocessCcDeclarationForm = documentprocessCcDeclarationFormRepository.save(documentprocessCcDeclarationForm)
                if (StringUtils.isNotBlank(documentprocessCcDeclarationFormMap["attachedFiles"] as? String )) {
                    attachedFileService.addFormInstAttachedFile(documentprocessCcDeclarationFormMap["attachedFiles"].toString(), formInstId, "documentprocess_cc_declarationForm", documentprocessCcDeclarationForm.id)
                }
                var documentprocessCcDfTableList = documentprocessCcDeclarationFormMap["documentprocess_cc_df_table"] as List<Map<String, Any>>?
                var documentprocessCcDfTables: List<DocumentprocessCcDfTable>? = null
                if (documentprocessCcDfTableList != null) {
                    documentprocessCcDfTables = documentprocessCcDfTableList.mapTo(ArrayList(), {
                        with(createEntityByMap<DocumentprocessCcDfTable>(it, DocumentprocessCcDfTable::class.java)) {
                            this.id = null
                            this.formInstId = formInstId
                            this.dfId = documentprocessCcDeclarationForm.id
                            this
                        }
                    })
                }
                var tables = documentprocessCcDfTableRepository.findByFormInstIdAndDfId(formInstId, documentprocessCcDeclarationForm.id!!)
                documentprocessCcDfTableRepository.delete(tables)
                if(documentprocessCcDfTables != null){
                    documentprocessCcDfTableRepository.save(documentprocessCcDfTables)
                }
            }
            //申报要素
            var documentprocessCcDeclarationElementsMap = documentprocessCcMap["documentprocess_cc_declarationElements"] as Map<String, Any>?
            if (documentprocessCcDeclarationElementsMap != null) {
                var documentprocessCcDeclarationElements = createEntityByMap<DocumentprocessCcDeclarationElements>(documentprocessCcDeclarationElementsMap, DocumentprocessCcDeclarationElements::class.java)
                documentprocessCcDeclarationElements.formInstId = formInstId
                documentprocessCcDeclarationElements = documentprocessCcDeclarationElementsRepository.save(documentprocessCcDeclarationElements)
                if (StringUtils.isNotBlank(documentprocessCcDeclarationElementsMap["attachedFiles"] as? String )) {
                    attachedFileService.addFormInstAttachedFile(documentprocessCcDeclarationElementsMap["attachedFiles"].toString(), formInstId, "documentprocess_cc_declarationElements", documentprocessCcDeclarationElements.id)
                }
                var documentprocessCcDeDefList = documentprocessCcDeclarationElementsMap["documentprocess_cc_de_def"] as List<Map<String, Any>>?
                var documentprocessCcDeDefs: List<DocumentprocessCcDeDef>? = null
                if (documentprocessCcDeDefList != null) {
                    documentprocessCcDeDefs = documentprocessCcDeDefList.mapTo(ArrayList(), {
                        with(createEntityByMap<DocumentprocessCcDeDef>(it, DocumentprocessCcDeDef::class.java)) {
                            this.id = null
                            this.formInstId = formInstId
                            this.deId = documentprocessCcDeclarationElements.id
                            this
                        }
                    })
                }
                var tables = documentprocessCcDeDefRepository.findByFormInstIdAndDeId(formInstId, documentprocessCcDeclarationElements.id!!)
                documentprocessCcDeDefRepository.delete(tables)
                if(documentprocessCcDeDefs != null){
                    documentprocessCcDeDefRepository.save(documentprocessCcDeDefs)
                }
            }
        }
        //---------------------单证员报关----------------------
        //---------------------向工厂索要发票----------------------
        var documentprocessAskInvoiceMap = map["documentprocess_askInvoice"] as Map<String, Any>?
        if (documentprocessAskInvoiceMap != null) {
            var documentprocessAskInvoice = createEntityByMap<DocumentprocessAskInvoice>(documentprocessAskInvoiceMap, DocumentprocessAskInvoice::class.java)
            documentprocessAskInvoice.formInstId = formInstId
            documentprocessAskInvoice = documentprocessAskInvoiceRepository.save(documentprocessAskInvoice)
            if (StringUtils.isNotBlank(documentprocessAskInvoiceMap["attachedFiles"] as? String)) {
                attachedFileService.addFormInstAttachedFile(documentprocessAskInvoiceMap["attachedFiles"].toString(), formInstId, "documentprocess_askInvoice", documentprocessAskInvoice.id)
            }
            var documentprocessAskiTableList = documentprocessAskInvoiceMap["documentprocess_aski_table"] as List<Map<String, Any>>?
            var documentprocessAskiTables: List<DocumentprocessAskiTable>? = null
            if (documentprocessAskiTableList != null) {
                documentprocessAskiTables = documentprocessAskiTableList.mapTo(ArrayList(), {
                    with(createEntityByMap<DocumentprocessAskiTable>(it, DocumentprocessAskiTable::class.java)) {
                        this.id = null
                        this.formInstId = formInstId
                        this.askiId = documentprocessAskInvoice.id
                        this
                    }
                })
            }
            var tables = documentprocessAskiTableRepository.findByFormInstIdAndAskiId(formInstId, documentprocessAskInvoice.id!!)
            documentprocessAskiTableRepository.delete(tables)
            if(documentprocessAskiTables != null){
                documentprocessAskiTableRepository.save(documentprocessAskiTables)
            }
        }
        //---------------------向工厂索要发票----------------------
        //---------------------核销资料（附件）----------------------
        var documentprocessCollectionDataMap = map["documentprocess_collectionData"] as Map<String, Any>?
        if (documentprocessCollectionDataMap != null) {
            var documentprocessCollectionData = createEntityByMap<DocumentprocessCollectionData>(documentprocessCollectionDataMap, DocumentprocessCollectionData::class.java)
            documentprocessCollectionData.formInstId = formInstId
            documentprocessCollectionData = documentprocessCollectionDataRepository.save(documentprocessCollectionData)
            if (StringUtils.isNotBlank(documentprocessCollectionDataMap["attachedFiles"] as? String)) {
                attachedFileService.addFormInstAttachedFile(documentprocessCollectionDataMap["attachedFiles"].toString(), formInstId, "documentprocess_collectionData", documentprocessCollectionData.id)
            }
        }
        //---------------------核销资料（附件）----------------------
    }

    override fun query(formInstId: Long): MutableMap<String, Any?> {
        var map = mutableMapOf<String, Any?>()
        //---------------------工厂发货----------------------
        var documentprocessFd = DocumentprocessFd()
        //出厂确认
        var documentProcessFdConfirm = documentProcessFdConfirmRepository.findByFormInstId(formInstId)
        if (documentProcessFdConfirm != null) {
            documentProcessFdConfirm.attachedFileList = attachedFileService.getFormAttachedFiles(formInstId, documentProcessFdConfirm.id, "documentprocess_fd_confirm")
        }

        //发货通知单
        var documentProcessFdNotice = documentProcessFdNoticeRepository.findByFormInstId(formInstId)
        if (documentProcessFdNotice != null) {
            documentProcessFdNotice.attachedFileList = attachedFileService.getFormAttachedFiles(formInstId, documentProcessFdNotice.id, "documentprocess_fd_notice")
            documentProcessFdNotice.documentprocess_fdn_fc_dff_contacts = documentProcessFdnFcDffContactRepository.findByFormInstIdAndDpfdId(formInstId, documentProcessFdNotice.id!!)
            documentProcessFdNotice.documentprocess_deliDetail = documentprocessDeliDetailRepository.findByFormInstIdAndDpfdId(formInstId, documentProcessFdNotice.id!!)
            documentProcessFdNotice.documentprocess_fdn_lcc_dfl_contacts = documentprocessFdnLccDflContactRepository.findByFormInstIdAndDpfdId(formInstId, documentProcessFdNotice.id!!)
            documentprocessFd.documentProcess_fd_notice = documentProcessFdNotice
            documentprocessFd.documentProcess_fd_confirm = documentProcessFdConfirm
        }
        map["documentprocess_fd"] = documentprocessFd
        //---------------------工厂发货----------------------
        //---------------------单证员报关----------------------
        var documentprocessCc = DocumentprocessCc()
        //货运委托书
        var documentprocessCcLetterOfDelivery = documentprocessCcLetterOfDeliveryRepository.findByFormInstId(formInstId)
        if (documentprocessCcLetterOfDelivery != null) {
            documentprocessCcLetterOfDelivery.attachedFileList = attachedFileService.getFormAttachedFiles(formInstId, documentprocessCcLetterOfDelivery.id, "documentprocess_cc_letterOfDelivery")
            documentprocessCc.documentprocess_cc_letterOfDelivery = documentprocessCcLetterOfDelivery
        }
        //报关发票
        var documentprocessCcCustomsDeclarationInvoice = documentprocessCcCustomsDeclarationInvoiceRepository.findByFormInstId(formInstId)
        if (documentprocessCcCustomsDeclarationInvoice != null) {
            documentprocessCcCustomsDeclarationInvoice.attachedFileList = attachedFileService.getFormAttachedFiles(formInstId, documentprocessCcCustomsDeclarationInvoice.id, "documentprocess_cc_customsDeclarationInvoice")
            documentprocessCcCustomsDeclarationInvoice.documentprocess_cc_cdi_table = documentprocessCcCdiTableRepository.findByFormInstIdAndCdiId(formInstId, documentprocessCcCustomsDeclarationInvoice.id!!)
            documentprocessCc.documentprocess_cc_customsDeclarationInvoice = documentprocessCcCustomsDeclarationInvoice
        }
        //报关箱单
        var documentprocessCcCustomsDeclarationBox = documentprocessCcCustomsDeclarationBoxRepository.findByFormInstId(formInstId)
        if (documentprocessCcCustomsDeclarationBox != null) {
            documentprocessCcCustomsDeclarationBox.attachedFileList = attachedFileService.getFormAttachedFiles(formInstId, documentprocessCcCustomsDeclarationBox.id, "documentprocess_cc_customsDeclarationBox")
            documentprocessCcCustomsDeclarationBox.documentprocess_cc_cdb_table = documentprocessCcCdbTableRepository.findByFormInstIdAndCdbId(formInstId, documentprocessCcCustomsDeclarationBox.id!!)
            documentprocessCc.documentprocess_cc_customsDeclarationBox = documentprocessCcCustomsDeclarationBox
        }
        //报关合同委托书
        var documentprocessCcCustomsDeclarationContract = documentprocessCcCustomsDeclarationContractRepository.findByFormInstId(formInstId)
        if (documentprocessCcCustomsDeclarationContract != null) {
            documentprocessCcCustomsDeclarationContract.attachedFileList = attachedFileService.getFormAttachedFiles(formInstId, documentprocessCcCustomsDeclarationContract.id, "documentprocess_cc_customsDeclarationContract")
            documentprocessCc.documentprocess_cc_customsDeclarationContract = documentprocessCcCustomsDeclarationContract
        }
        //报关单
        var documentprocessCcDeclarationForm = documentprocessCcDeclarationFormRepository.findByFormInstId(formInstId)
        if (documentprocessCcDeclarationForm != null) {
            documentprocessCcDeclarationForm.attachedFileList = attachedFileService.getFormAttachedFiles(formInstId, documentprocessCcDeclarationForm.id, "documentprocess_cc_declarationForm")
            documentprocessCcDeclarationForm.documentprocess_cc_df_table = documentprocessCcDfTableRepository.findByFormInstIdAndDfId(formInstId, documentprocessCcDeclarationForm.id!!)
            documentprocessCc.documentprocess_cc_declarationForm = documentprocessCcDeclarationForm
        }//申报要素
        var documentprocessCcDeclarationElements = documentprocessCcDeclarationElementsRepository.findByFormInstId(formInstId)
        if (documentprocessCcDeclarationElements != null) {
            documentprocessCcDeclarationElements.attachedFileList = attachedFileService.getFormAttachedFiles(formInstId, documentprocessCcDeclarationElements.id, "documentprocess_cc_declarationElements")
            documentprocessCcDeclarationElements.documentprocess_cc_de_def = documentprocessCcDeDefRepository.findByFormInstIdAndDeId(formInstId, documentprocessCcDeclarationElements.id!!)
            documentprocessCc.documentprocess_cc_declarationElements = documentprocessCcDeclarationElements
        }
        map["documentprocess_cc"] = documentprocessCc
        //---------------------单证员报关----------------------
        //---------------------向工厂索要发票----------------------
        var documentprocessAskInvoice = documentprocessAskInvoiceRepository.findByFormInstId(formInstId)
        if (documentprocessAskInvoice != null) {
            documentprocessAskInvoice.attachedFileList = attachedFileService.getFormAttachedFiles(formInstId, documentprocessAskInvoice.id, "documentprocess_askInvoice")
            documentprocessAskInvoice.documentprocess_aski_table = documentprocessAskiTableRepository.findByFormInstIdAndAskiId(formInstId, documentprocessAskInvoice.id!!)
        }
        map["documentprocess_askInvoice"] = documentprocessAskInvoice
        //---------------------向工厂索要发票----------------------
        //---------------------核销资料（附件）----------------------
        var documentprocessCollectionData = documentprocessCollectionDataRepository.findByFormInstId(formInstId)
        if (documentprocessCollectionData != null) {
            documentprocessCollectionData.attachedFileList = attachedFileService.getFormAttachedFiles(formInstId, documentprocessCollectionData.id, "documentprocess_collectionData")
        }
        map["documentprocess_collectionData"] = documentprocessCollectionData
        //---------------------核销资料（附件）----------------------
        return map
    }
}